package com.redstar.HappyRefresh.config;

import com.redstar.HappyRefresh.interceptor.InterceptorManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private InterceptorManage interceptorManage;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptorManage)
                .addPathPatterns("/admin/**", "/authorize/**")
                .addPathPatterns("/luckyjourney/**")
                .excludePathPatterns("/luckyjourney/login/**", "/luckyjourney/index/**", "/luckyjourney/cdn/**", "/luckyjourney/file/**");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        String[] url = {"http://127.0.0.1:5378", "http://localhost:5378"};
        registry.addMapping("/**")
                .allowedOrigins(url)
                .allowCredentials(true)
                .allowedMethods("*")   // 允许跨域的方法，可以单独配置
                .allowedHeaders("*");  // 允许跨域的请求头，可以单独配置;
    }
}
